﻿using System;
using System.Device.Location;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SydEnergiPrototype.Logic;
using SydEnergiPrototype.Model;

namespace SydEnergiPrototype.DataAccess
{
    public class DataRepositoryStub : IDataRepository
    {
        private static Cabinets _cabinets;
        public Cabinets Cabinets
        {
            get
            {
                if (_cabinets == null)
                    InitializeCabinets();
                return _cabinets;
            }
            set { _cabinets = value; }
        }

        public void GetCabinetsAsync(ReturnResult callback)
        {
            callback.Notify(Cabinets);
        }

        public void SetCabinetsAsync(Action callback, Cabinets cabinets)
        {
            Cabinets = cabinets;
            callback();
        }

        private void InitializeCabinets()
        {
            _cabinets = new Cabinets();

            //-----------------------------------TESTDATA--------------------------------//

            Cabinet Melvang = new Cabinet("SK107 ASK", new Address("Melvang", 2, 6600, "Vejen"), new GeoCoordinate(55.468443, 9.099147));
            Cabinet Pgade = new Cabinet("SK205 HAC", new Address("Præstegade", 26, 6100, "Haderslev"), new GeoCoordinate(55.24894, 9.484892));
            Cabinet Rentemester = new Cabinet("AF109 ASK", new Address("Rentemestervej", 2, "A", 2400, "København NV"),
                                              new GeoCoordinate(55.704096, 12.537503));
            Cabinet Rentemester40 = new Cabinet("SK106 ASK", new Address("Rentemestervej", 40, 2400, "København NV"),
                                                new GeoCoordinate(55.707082, 12.526882));
            Cabinet Hvidovre = new Cabinet("TU111 HAC", new Address("Hvidovrevej", 26, 2650, "Hvidovre"),
                                           new GeoCoordinate(55.670409, 12.475147));
            Cabinet Katholm = new Cabinet("TY222 ASK", new Address("Katholm", 212, 3670, "Veksø"),
                                          new GeoCoordinate(55.756586, 12.232053));
            Cabinet Holger = new Cabinet("UN890 HAC", new Address("Holger Drachmanns Vej", 1, 8000, "Aarhus"),
                                         new GeoCoordinate(56.165113, 10.196128));

            var entry = new Entry(Melvang.Id, new Address("Præstegade", 5, "A", "3", "Tv", 6600, "Vejen"),
                                  new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Orange), new History());
            entry.Cable = "Blæsefiber 8 SM, Emtelle";
            entry.Cassette = 7;
            entry.InnerTube = 4;
            entry.InnerTubeId = "B";
            entry.LsseMb = "MB-9";
            entry.Teletube = "7x5mm102 7x5 B";
            entry.Position = 3;
            entry.FiberNumber = 1;

            var historyEntry = new HistoryEntry(DateTime.Now, "M. Rylander", "Oprettet", "Kommentar...");
            entry.EntryHistory.Add(historyEntry);

            Melvang.EntryCollection.Add(entry);
            Melvang.EntryCollection.Add(new Entry(Melvang.Id, new Address("Klosteret", 9, 6600, "Vejen"),
                                                  new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Orange), new History()));

            Pgade.EntryCollection.Add(new Entry(Pgade.Id, new Address("Nogetandet", 5, 6100, "Haderslev"),
                                                new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.Orange), new History()));
            Pgade.EntryCollection.Add(new Entry(Pgade.Id, new Address("Valbylanggade", 9, 6100, "Haderslev"),
                                                new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.Orange), new History()));

            Rentemester.EntryCollection.Add(new Entry(Rentemester.Id, new Address("Bygmestervej", 5, 2400, "København NV"),
                                                      new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Red), new History()));

            Rentemester40.EntryCollection.Add(new Entry(Rentemester40.Id, new Address("Bygmestervej", 19, 2400, "København NV"),
                                                        new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.Red), new History()));
            Rentemester40.EntryCollection.Add(new Entry(Rentemester40.Id, new Address("Bygmestervej", 50, 2400, "København NV"),
                                                        new SolidColorBrush(Colors.Orange), new SolidColorBrush(Colors.Red), new History()));


            Hvidovre.EntryCollection.Add(new Entry(Hvidovre.Id, new Address("Brostykkevej", 5, 2650, "Hvidovre"),
                                                   new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Orange), new History()));
            Hvidovre.EntryCollection.Add(new Entry(Hvidovre.Id, new Address("Menelaos Blvd", 9, 2650, "Hvidovre"),
                                                   new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Orange), new History()));

            Katholm.EntryCollection.Add(new Entry(Katholm.Id, new Address("Katholm", 5, 3670, "Veksø"),
                                                  new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.Orange), new History()));
            Katholm.EntryCollection.Add(new Entry(Katholm.Id, new Address("Bygade", 9, 3670, "Veksø"),
                                                  new SolidColorBrush(Colors.Red), new SolidColorBrush(Colors.Orange), new History()));

            Holger.EntryCollection.Add(new Entry(Holger.Id, new Address("Sognevej", 5, 8000, "Aarhus"),
                                                 new SolidColorBrush(Colors.Blue), new SolidColorBrush(Colors.Red), new History()));

            _cabinets.Add(Melvang);
            _cabinets.Add(Pgade);
            _cabinets.Add(Rentemester);
            _cabinets.Add(Rentemester40);
            _cabinets.Add(Hvidovre);
            _cabinets.Add(Katholm);
            _cabinets.Add(Holger);

            //-----------------------------------TESTDATA--------------------------------//
        }
    }
}
